package persistenceAndSerialization;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Dom4jTest {
	public static void main(String[] args) {
		SAXReader reader=new SAXReader();
		try {
			Document document = reader.read("sample.xml");
			Element root = document.getRootElement();
			List children = root.elements();
			for(Object obj:children){
				Element child=(Element)obj;
				if(!"student".equals(child.getName())){
					continue;
				}
				System.out.println("------student-----");
				System.out.println("id:"+child.attributeValue("id"));
				System.out.println("name:"+child.elementText("name"));
				System.out.println("gender:"+child.elementText("gender"));
				System.out.println("age:"+child.elementText("age"));
			}
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		
	}
}
